package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxTypeJyk;
import cn.stylefeng.guns.modular.lx.mapper.LxTypeJykMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxTypeJykParam;
import cn.stylefeng.guns.modular.lx.model.result.LxTypeJykResult;
import  cn.stylefeng.guns.modular.lx.service.LxTypeJykService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jyk
 * @since 2023-12-14
 */
@Service
public class LxTypeJykServiceImpl extends ServiceImpl<LxTypeJykMapper, LxTypeJyk> implements LxTypeJykService {

    @Override
    public void add(LxTypeJykParam param){
        LxTypeJyk entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxTypeJykParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxTypeJykParam param){
        LxTypeJyk oldEntity = getOldEntity(param);
        LxTypeJyk newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxTypeJykResult findBySpec(LxTypeJykParam param){
        return null;
    }

    @Override
    public List<LxTypeJykResult> findListBySpec(LxTypeJykParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxTypeJykParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxTypeJykParam param){
        return param.getTid();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxTypeJyk getOldEntity(LxTypeJykParam param) {
        return this.getById(getKey(param));
    }

    private LxTypeJyk getEntity(LxTypeJykParam param) {
        LxTypeJyk entity = new LxTypeJyk();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
